<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">


























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.0.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/Peppa.png?v=7.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/Peppa.jpg?v=7.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/Peppa.jpg?v=7.0.0">








<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.0.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="A Water The GardenA 题目大意给定 $n$ 块连续的土地，编号 $1 ~ n$。有 $k$ 块土地上有水龙头（第 $i$ 个水龙头位于编号 $x_i$ 的土地上）。 当在 $x_i$ 土地上的水龙头打开后，$j$ 秒后，编号在 $[x_i - (j - 1), x_i + (j - 1)]$ 区间里的土地均会被灌溉。 注意，可以认为水流为离散的，当不到整秒数时，水流没有任何变化，">
<meta name="keywords" content="ACM,Tutorial,CodeForces">
<meta property="og:type" content="article">
<meta property="og:title" content="CodeForces 920 Educational Codeforces Round 37">
<meta property="og:url" content="https://linxi99.gitee.io/20200228/CodeForces-920-Educational-Codeforces-Round-37/index.html">
<meta property="og:site_name" content="linxi&#39;s dream">
<meta property="og:description" content="A Water The GardenA 题目大意给定 $n$ 块连续的土地，编号 $1 ~ n$。有 $k$ 块土地上有水龙头（第 $i$ 个水龙头位于编号 $x_i$ 的土地上）。 当在 $x_i$ 土地上的水龙头打开后，$j$ 秒后，编号在 $[x_i - (j - 1), x_i + (j - 1)]$ 区间里的土地均会被灌溉。 注意，可以认为水流为离散的，当不到整秒数时，水流没有任何变化，">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-02-29T12:37:53.156Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="CodeForces 920 Educational Codeforces Round 37">
<meta name="twitter:description" content="A Water The GardenA 题目大意给定 $n$ 块连续的土地，编号 $1 ~ n$。有 $k$ 块土地上有水龙头（第 $i$ 个水龙头位于编号 $x_i$ 的土地上）。 当在 $x_i$ 土地上的水龙头打开后，$j$ 秒后，编号在 $[x_i - (j - 1), x_i + (j - 1)]$ 区间里的土地均会被灌溉。 注意，可以认为水流为离散的，当不到整秒数时，水流没有任何变化，">






  <link rel="canonical" href="https://linxi99.gitee.io/20200228/CodeForces-920-Educational-Codeforces-Round-37/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>CodeForces 920 Educational Codeforces Round 37 | linxi's dream</title>
  






  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b4099cd89c9f33abab06a03748dac801";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>







  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">linxi's dream</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">穷且益坚，不坠青云之志</p>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://linxi99.gitee.io/20200228/CodeForces-920-Educational-Codeforces-Round-37/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linxi">
      <meta itemprop="description" content="stay hungry, stay foolish">
      <meta itemprop="image" content="/images/star.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linxi's dream">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">CodeForces 920 Educational Codeforces Round 37

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2020-02-28 21:14:16" itemprop="dateCreated datePublished" datetime="2020-02-28T21:14:16+08:00">2020-02-28</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-02-29 20:37:53" itemprop="dateModified" datetime="2020-02-29T20:37:53+08:00">2020-02-29</time>
              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing"><a href="/categories/Contests/" itemprop="url" rel="index"><span itemprop="name">Contests</span></a></span>

                
                
              
            </span>
          

          
            
            
              
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
            
                <span class="post-meta-item-text">评论数：</span>
                <a href="/20200228/CodeForces-920-Educational-Codeforces-Round-37/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/20200228/CodeForces-920-Educational-Codeforces-Round-37/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
            <span id="/20200228/CodeForces-920-Educational-Codeforces-Round-37/" class="leancloud_visitors" data-flag-title="CodeForces 920 Educational Codeforces Round 37">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              
                <span class="post-meta-item-text">阅读次数：</span>
              
                <span class="leancloud-visitors-count"></span>
            </span>
            <span class="post-meta-divider">|
            </span> <span title="post.wordcount">
            <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
            </span>字数： 3.3k
            </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="A-Water-The-Garden"><a href="#A-Water-The-Garden" class="headerlink" title="A Water The Garden"></a>A Water The Garden</h2><h3 id="A-题目大意"><a href="#A-题目大意" class="headerlink" title="A 题目大意"></a>A 题目大意</h3><p>给定 $n$ 块连续的土地，编号 $1 ~ n$。有 $k$ 块土地上有水龙头（第 $i$ 个水龙头位于编号 $x_i$ 的土地上）。</p>
<p>当在 $x_i$ 土地上的水龙头打开后，$j$ 秒后，编号在 $[x_i - (j - 1), x_i + (j - 1)]$ 区间里的土地均会被灌溉。</p>
<p>注意，可以认为水流为离散的，当不到整秒数时，水流没有任何变化，一到整秒数，瞬间灌溉下一块土地。</p>
<a id="more"></a>
<h3 id="A-解题思路"><a href="#A-解题思路" class="headerlink" title="A 解题思路"></a>A 解题思路</h3><p>根据题意，每两个水龙头之间的所有空地全部灌溉所需要的时间是 $(delta - 1)/2 + 1$</p>
<p>因此对所有相邻两两水龙头之间空地灌溉所需要的时间，取最大值，即基本解决问题。</p>
<p>注意考虑第一个水龙头以前的所有空地，和最后一个水龙头以后的所有空地。</p>
<h3 id="A-代码实现"><a href="#A-代码实现" class="headerlink" title="A 代码实现"></a>A 代码实现</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"><span class="keyword">import</span> java.util.StringTokenizer;</span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> maxn = (<span class="keyword">int</span>) (<span class="number">2e2</span> + <span class="number">5</span>);</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] x = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        InputStream inputStream = System.in;</span><br><span class="line">        InputReader in = <span class="keyword">new</span> InputReader(inputStream);</span><br><span class="line">        <span class="keyword">int</span> T = in.nextInt();</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> cs = <span class="number">1</span>; cs &lt;= T; ++cs) &#123;</span><br><span class="line">            <span class="keyword">int</span> n = in.nextInt();</span><br><span class="line">            <span class="keyword">int</span> k = in.nextInt();</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= k; ++i) &#123;</span><br><span class="line">                x[i] = in.nextInt();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">int</span> ans = Math.max(x[<span class="number">1</span>], n - x[k] + <span class="number">1</span>);</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; k; ++i) &#123;</span><br><span class="line">                <span class="keyword">int</span> dt = x[i + <span class="number">1</span>] - x[i] + <span class="number">1</span>;</span><br><span class="line">                ans = Math.max(ans, (dt + <span class="number">1</span>)/<span class="number">2</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(ans);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// Scanner in = new Scanner(System.in);</span></span><br><span class="line">        <span class="comment">// in.close();</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">InputReader</span> </span>&#123;</span><br><span class="line">        <span class="keyword">public</span> BufferedReader reader;</span><br><span class="line">        <span class="keyword">public</span> StringTokenizer tokenizer;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="title">InputReader</span><span class="params">(InputStream stream)</span> </span>&#123;</span><br><span class="line">            reader = <span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(stream), <span class="number">32768</span>);</span><br><span class="line">            tokenizer = <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> String <span class="title">next</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">while</span>(tokenizer == <span class="keyword">null</span> || !tokenizer.hasMoreTokens()) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    tokenizer = <span class="keyword">new</span> StringTokenizer(reader.readLine());</span><br><span class="line">                &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(e);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> tokenizer.nextToken();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">nextInt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Integer.parseInt(next());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">nextLong</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Long.parseLong(next());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="B-Tea-Queue"><a href="#B-Tea-Queue" class="headerlink" title="B Tea Queue"></a>B Tea Queue</h2><h3 id="B-题目大意"><a href="#B-题目大意" class="headerlink" title="B 题目大意"></a>B 题目大意</h3><p>现有一队人排长队接水喝。</p>
<p>第 $i$ 个人在第 $l_i$ 分钟开始时来到队尾。如果同时有多个人来到队尾，下标小的排在前面。</p>
<p>每分钟队首那个人可以接水，就在这一分钟接水，下一分钟开始前离开队列。</p>
<p>如果某人等到第 $r_i$ 分钟开始还没排到接水，他也会空瓶离开。</p>
<p>请计算每个人接到水的时刻，或者接不到水输出0。</p>
<h3 id="B-解题思路"><a href="#B-解题思路" class="headerlink" title="B 解题思路"></a>B 解题思路</h3><p>根据题意，按照时间顺序模拟即可。</p>
<h3 id="B-代码实现"><a href="#B-代码实现" class="headerlink" title="B 代码实现"></a>B 代码实现</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"><span class="keyword">import</span> java.util.StringTokenizer;</span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> maxn = (<span class="keyword">int</span>) (<span class="number">1e3</span> + <span class="number">5</span>);</span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">stu</span> <span class="keyword">implements</span> <span class="title">Comparable</span>&lt;<span class="title">stu</span>&gt;</span>&#123;</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">int</span> lf;</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">int</span> rt;</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">int</span> id;</span><br><span class="line">        stu(<span class="keyword">int</span> l, <span class="keyword">int</span> r, <span class="keyword">int</span> i) &#123;</span><br><span class="line">            lf = l;</span><br><span class="line">            rt = r;</span><br><span class="line">            id = i;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">compareTo</span><span class="params">(stu rhs)</span> </span>&#123;</span><br><span class="line">            <span class="keyword">if</span>(lf == rhs.lf) <span class="keyword">return</span> id - rhs.id;</span><br><span class="line">            <span class="keyword">return</span> lf - rhs.lf;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] ans = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> stu[] s = <span class="keyword">new</span> stu[maxn];</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        InputStream inputStream = System.in;</span><br><span class="line">        InputReader in = <span class="keyword">new</span> InputReader(inputStream);</span><br><span class="line">        <span class="keyword">int</span> T = in.nextInt();</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> cs = <span class="number">1</span>; cs &lt;= T; ++cs) &#123;</span><br><span class="line">            <span class="keyword">int</span> n = in.nextInt();</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">                <span class="keyword">int</span> lf = in.nextInt();</span><br><span class="line">                <span class="keyword">int</span> rt = in.nextInt();</span><br><span class="line">                s[i] = <span class="keyword">new</span> stu(lf, rt, i);</span><br><span class="line">            &#125;</span><br><span class="line">            Arrays.sort(s, <span class="number">0</span>, n);</span><br><span class="line">            <span class="keyword">int</span> now = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">                <span class="comment">// System.out.println(s[i].id + ": " + s[i].lf + ", " + s[i].rt);</span></span><br><span class="line">                <span class="keyword">if</span>(now &lt; s[i].lf) &#123;</span><br><span class="line">                    ans[s[i].id] = s[i].lf;</span><br><span class="line">                    now = s[i].lf + <span class="number">1</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span>(now &gt; s[i].rt) &#123;</span><br><span class="line">                    ans[s[i].id] = <span class="number">0</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    ans[s[i].id] = now;</span><br><span class="line">                    ++now;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">                <span class="keyword">if</span>(i &gt; <span class="number">0</span>) System.out.print(<span class="string">" "</span>);</span><br><span class="line">                System.out.print(ans[i]);</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// Scanner in = new Scanner(System.in);</span></span><br><span class="line">        <span class="comment">// in.close();</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">InputReader</span> </span>&#123;</span><br><span class="line">        <span class="keyword">public</span> BufferedReader reader;</span><br><span class="line">        <span class="keyword">public</span> StringTokenizer tokenizer;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="title">InputReader</span><span class="params">(InputStream stream)</span> </span>&#123;</span><br><span class="line">            reader = <span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(stream), <span class="number">32768</span>);</span><br><span class="line">            tokenizer = <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> String <span class="title">next</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">while</span>(tokenizer == <span class="keyword">null</span> || !tokenizer.hasMoreTokens()) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    tokenizer = <span class="keyword">new</span> StringTokenizer(reader.readLine());</span><br><span class="line">                &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(e);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> tokenizer.nextToken();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">nextInt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Integer.parseInt(next());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">nextLong</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Long.parseLong(next());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="C-Swap-Adjacent-Elements"><a href="#C-Swap-Adjacent-Elements" class="headerlink" title="C Swap Adjacent Elements"></a>C Swap Adjacent Elements</h2><h3 id="C-题目大意"><a href="#C-题目大意" class="headerlink" title="C 题目大意"></a>C 题目大意</h3><p>给定一个 $n$ 的全排列 $a$，$1 ~ n$ 每个数字在序列里出现且仅出现一次。</p>
<p>给定一个长度为 $n - 1$ 的布尔数组 $b$，$b_i$ 表示 $a$ 数组中的 $i$ 位置，能否与 $i + 1$ 位置交换。</p>
<p>你可以对任何允许交换的相邻位置，以任意顺序，交换任意次。</p>
<p>请问能否将序列 $a$ 变为升序序列。</p>
<h3 id="C-解题思路"><a href="#C-解题思路" class="headerlink" title="C 解题思路"></a>C 解题思路</h3><p>考虑冒泡排序过程，主要操作便是相邻位置两两交换。</p>
<p>显然，序列 $a$ 中的第 $i$ 数字 $a_i$ 能否交换到它应该在的位置，也就是第 $a_i$ 个位置，只需要看，$a_i$ 位置与 $i$ 位置之间的所有 $b$ 数组，是否都为允许交换。</p>
<p>也就是说，把每一个位置看成一个点，每个允许交换看成一条边，则只需要判断点 $i$ 与点 $a_i$ 是否在同一联通块内。</p>
<p>由于题目的性质，无需使用并查集维护联通关系，只需要从左到右顺序染色即可（具体实现见代码）。</p>
<h3 id="C-代码实现"><a href="#C-代码实现" class="headerlink" title="C 代码实现"></a>C 代码实现</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">import</span> java.io.OutputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.PrintWriter;</span><br><span class="line"><span class="keyword">import</span> java.math.BigInteger;</span><br><span class="line"><span class="keyword">import</span> java.util.StringTokenizer;</span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> maxn = (<span class="keyword">int</span>) (<span class="number">2e5</span> + <span class="number">5</span>);</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] col = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] id = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> String s;</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">solve</span><span class="params">(<span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">            <span class="keyword">if</span>(col[i] != col[id[i]]) <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        InputStream inputStream = System.in;</span><br><span class="line">        InputReader in = <span class="keyword">new</span> InputReader(inputStream);</span><br><span class="line">        <span class="keyword">int</span> n = in.nextInt();</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">            id[i] = in.nextInt();</span><br><span class="line">            --id[i];</span><br><span class="line">        &#125;</span><br><span class="line">        s = in.next();</span><br><span class="line">        col[<span class="number">0</span>] = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n - <span class="number">1</span>; ++i) &#123;</span><br><span class="line">            <span class="keyword">char</span> ch = s.charAt(i);</span><br><span class="line">            <span class="keyword">if</span>(ch == <span class="string">'0'</span>) col[i + <span class="number">1</span>] = col[i] + <span class="number">1</span>;</span><br><span class="line">            <span class="keyword">else</span> col[i + <span class="number">1</span>] = col[i];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(solve(n)) &#123;</span><br><span class="line">            System.out.println(<span class="string">"YES"</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            System.out.println(<span class="string">"NO"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// Scanner in = new Scanner(System.in);</span></span><br><span class="line">        <span class="comment">// in.close();</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">InputReader</span> </span>&#123;</span><br><span class="line">        <span class="keyword">public</span> BufferedReader reader;</span><br><span class="line">        <span class="keyword">public</span> StringTokenizer tokenizer;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="title">InputReader</span><span class="params">(InputStream stream)</span> </span>&#123;</span><br><span class="line">            reader = <span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(stream), <span class="number">32768</span>);</span><br><span class="line">            tokenizer = <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> String <span class="title">next</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">while</span>(tokenizer == <span class="keyword">null</span> || !tokenizer.hasMoreTokens()) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    tokenizer = <span class="keyword">new</span> StringTokenizer(reader.readLine());</span><br><span class="line">                &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(e);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> tokenizer.nextToken();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">nextInt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Integer.parseInt(next());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">nextLong</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Long.parseLong(next());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="E-Connected-Components"><a href="#E-Connected-Components" class="headerlink" title="E Connected Components"></a>E Connected Components</h2><h3 id="E-题目大意"><a href="#E-题目大意" class="headerlink" title="E 题目大意"></a>E 题目大意</h3><p>给定一张 $n$ 个点，$(1 \le n \le 2 \times 10 ^5)$， $m$ 条边 $(0 \le m \le 2 \times 10 ^5)$ 的无向图。</p>
<p>求它的补图共有多少个联通块。并按照升序输出这些联通块的大小。</p>
<h3 id="E-解题思路"><a href="#E-解题思路" class="headerlink" title="E 解题思路"></a>E 解题思路</h3><p>由于补图的边数规模最大可达 $\frac{n \times (n - 1)}{2}$，因此正常建图跑 $bfs$ 或 $dfs$ 显然不可行。</p>
<p>考虑改进 $bfs$，我们考虑对某一个未访问点过的点 $x$ 进行 $bfs$，然后依次访问点 $x$ 在原图中连出去的边 $xy$，显然与 $x$ 相邻的这些 $y$，在补图中与 $x$ 不相邻。</p>
<p>同时我们维护一个链表，存储未访问过的所有点。</p>
<p>这时我们只需要遍历链表，将所有在补图中与 $x$ 相邻的点，全都加入到 $bfs$ 队列中，顺便在链表中删除对应的点，并将其状态设定为已访问过即可。</p>
<p>通过均摊分析时间复杂度，每个节点会且只会入队一次，每条边会且只会被访问两次，时间复杂度为 $O(n + m)$，可以通过此题。</p>
<h3 id="E-代码实现"><a href="#E-代码实现" class="headerlink" title="E 代码实现"></a>E 代码实现</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"><span class="keyword">import</span> java.util.StringTokenizer;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"><span class="keyword">import</span> java.io.OutputStreamWriter;</span><br><span class="line"><span class="keyword">import</span> java.io.PrintWriter;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> maxn = (<span class="keyword">int</span>) (<span class="number">2e6</span> + <span class="number">5</span>);</span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">Edge</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> nxt;</span><br><span class="line">        <span class="keyword">int</span> to;</span><br><span class="line">        Edge(<span class="keyword">int</span> _nxt, <span class="keyword">int</span> _to) &#123;</span><br><span class="line">            nxt = _nxt;</span><br><span class="line">            to = _to;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> Edge[] E = <span class="keyword">new</span> Edge[maxn*<span class="number">2</span>];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] head =  <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] lnxt =  <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] llst =  <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> fst;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> Etot;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> Ctot;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] C = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] q = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> lf;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> rt;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">boolean</span>[] vis = <span class="keyword">new</span> <span class="keyword">boolean</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] cnt = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] col = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">addEdge</span><span class="params">(<span class="keyword">int</span> u, <span class="keyword">int</span> v)</span> </span>&#123;</span><br><span class="line">        E[Etot] = <span class="keyword">new</span> Edge(head[u], v);</span><br><span class="line">        head[u] = Etot++;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">bfs</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">        lf = rt = <span class="number">0</span>;</span><br><span class="line">        q[rt++] = x;</span><br><span class="line">        col[Ctot] = <span class="number">0</span>;</span><br><span class="line">        vis[x] = <span class="keyword">true</span>;</span><br><span class="line">        <span class="keyword">if</span>(x == fst) &#123;</span><br><span class="line">            fst = lnxt[fst];</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">if</span>(lnxt[x] != -<span class="number">1</span>) llst[lnxt[x]] = llst[x];</span><br><span class="line">            <span class="keyword">if</span>(llst[x] != -<span class="number">1</span>) lnxt[llst[x]] = lnxt[x];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">while</span>(lf &lt; rt) &#123;</span><br><span class="line">            <span class="keyword">int</span> now = q[lf++];</span><br><span class="line">            ++col[Ctot];</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i = head[now]; i != -<span class="number">1</span>; i = E[i].nxt) &#123;</span><br><span class="line">                <span class="keyword">int</span> to = E[i].to;</span><br><span class="line">                ++cnt[to];</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">int</span> id = fst;</span><br><span class="line">            <span class="keyword">while</span>(id != -<span class="number">1</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span>(!vis[id] &amp;&amp; cnt[id] == <span class="number">0</span>) &#123;</span><br><span class="line">                    vis[id] = <span class="keyword">true</span>;</span><br><span class="line">                    q[rt++] = id;</span><br><span class="line">                    <span class="keyword">if</span>(id == fst) &#123;</span><br><span class="line">                        fst = lnxt[fst];</span><br><span class="line">                        <span class="keyword">if</span>(fst != -<span class="number">1</span>) llst[fst] = -<span class="number">1</span>;</span><br><span class="line">                    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                        <span class="keyword">if</span>(lnxt[id] != -<span class="number">1</span>) llst[lnxt[id]] = llst[id];</span><br><span class="line">                        <span class="keyword">if</span>(llst[id] != -<span class="number">1</span>) lnxt[llst[id]] = lnxt[id];</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                id = lnxt[id];</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i = head[now]; i != -<span class="number">1</span>; i = E[i].nxt) &#123;</span><br><span class="line">                <span class="keyword">int</span> to = E[i].to;</span><br><span class="line">                --cnt[to];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        ++Ctot;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        InputStream inputStream = System.in;</span><br><span class="line">        InputReader in = <span class="keyword">new</span> InputReader(inputStream);</span><br><span class="line">        <span class="keyword">int</span> n = in.nextInt();</span><br><span class="line">        <span class="keyword">int</span> m = in.nextInt();</span><br><span class="line">        llst[<span class="number">1</span>] = -<span class="number">1</span>;</span><br><span class="line">        lnxt[n] = -<span class="number">1</span>;</span><br><span class="line">        Etot = Ctot = lf = rt = <span class="number">0</span>;</span><br><span class="line">        fst = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= n; ++i) &#123;</span><br><span class="line">            head[i] = -<span class="number">1</span>;</span><br><span class="line">            vis[i] = <span class="keyword">false</span>;</span><br><span class="line">            cnt[i] = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">if</span>(i &gt; <span class="number">1</span>) llst[i] = i - <span class="number">1</span>;</span><br><span class="line">            <span class="keyword">if</span>(i &lt; n) lnxt[i] = i + <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; m; ++i) &#123;</span><br><span class="line">            <span class="keyword">int</span> u = in.nextInt();</span><br><span class="line">            <span class="keyword">int</span> v = in.nextInt();</span><br><span class="line">            addEdge(u, v);</span><br><span class="line">            addEdge(v, u);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= n; ++i) &#123;</span><br><span class="line">            <span class="keyword">if</span>(vis[i]) <span class="keyword">continue</span>;</span><br><span class="line">            bfs(i, n);</span><br><span class="line">        &#125;</span><br><span class="line">        Arrays.sort(col, <span class="number">0</span>, Ctot);</span><br><span class="line">        System.out.println(Ctot);</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; Ctot; ++i) &#123;</span><br><span class="line">            <span class="keyword">if</span>(i &gt; <span class="number">0</span>) System.out.print(<span class="string">" "</span>);</span><br><span class="line">            System.out.print(col[i]);</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println();</span><br><span class="line">        <span class="comment">// Scanner in = new Scanner(System.in);</span></span><br><span class="line">        <span class="comment">// in.close();</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">InputReader</span> </span>&#123;</span><br><span class="line">        <span class="keyword">public</span> BufferedReader reader;</span><br><span class="line">        <span class="keyword">public</span> StringTokenizer tokenizer;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="title">InputReader</span><span class="params">(InputStream stream)</span> </span>&#123;</span><br><span class="line">            reader = <span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(stream), <span class="number">32768</span>);</span><br><span class="line">            tokenizer = <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> String <span class="title">next</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">while</span>(tokenizer == <span class="keyword">null</span> || !tokenizer.hasMoreTokens()) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    tokenizer = <span class="keyword">new</span> StringTokenizer(reader.readLine());</span><br><span class="line">                &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(e);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> tokenizer.nextToken();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">nextInt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Integer.parseInt(next());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">nextLong</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Long.parseLong(next());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="F-SUM-and-REPLACE"><a href="#F-SUM-and-REPLACE" class="headerlink" title="F SUM and REPLACE"></a>F SUM and REPLACE</h2><h3 id="F-题目大意"><a href="#F-题目大意" class="headerlink" title="F 题目大意"></a>F 题目大意</h3><p>给定一个长度为 $n$ $(1 \le n \le 3 \times 10 ^5)$ 的正整数数组 $(1 \le a _ i \le 10 ^ 6)$，并对数组进行 $m$ $(1 \le m \le 3 \times 10 ^5)$ 次询问。</p>
<p>询问分为两种：</p>
<p>询问一：对区间 $[l, r]$ 的所有数字，值变为其正因数个数。</p>
<p>询问二：询问区间 $[l, r]$ 的总和。</p>
<h3 id="F-解题思路"><a href="#F-解题思路" class="headerlink" title="F 解题思路"></a>F 解题思路</h3><p>由于因数个数为积性函数，且数组值域为 $[1, 10 ^ 6]$，因此可以使用积性函数线性筛，预处理值域内所有数的因数个数。</p>
<p>我们观察因数个数数组，我们发现 $1, 2$ 这两个点为不动点，对这两个值求因数个数已经不再变化。</p>
<p>而且对于值域内的任何一个数连续进行取因数个数操作，很快就会收敛到不动点。</p>
<p>因此我们借鉴区间开平方类似题目的做法，用线段树进行相应维护。</p>
<p>若区间最大值小于等于 $2$，则无需下放，操作不会再对对应区间产生影响。</p>
<p>若区间最大值大于 $2$，则暴力下放，由于其性质，每个点最多被操作不超过 $10$ 次。</p>
<p>修改时用线段树顺手维护区间和即可。</p>
<h3 id="F-代码实现"><a href="#F-代码实现" class="headerlink" title="F 代码实现"></a>F 代码实现</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"><span class="keyword">import</span> java.util.StringTokenizer;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"><span class="keyword">import</span> java.io.OutputStreamWriter;</span><br><span class="line"><span class="keyword">import</span> java.io.PrintWriter;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> maxn = (<span class="keyword">int</span>) (<span class="number">3e5</span> + <span class="number">5</span>);</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> maxm = (<span class="keyword">int</span>) (<span class="number">1e6</span> + <span class="number">5</span>);</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] a = <span class="keyword">new</span> <span class="keyword">int</span>[maxn];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] d = <span class="keyword">new</span> <span class="keyword">int</span>[maxm];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] num = <span class="keyword">new</span> <span class="keyword">int</span>[maxm];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span>[] p = <span class="keyword">new</span> <span class="keyword">int</span>[maxm];</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> tot;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">boolean</span>[] np = <span class="keyword">new</span> <span class="keyword">boolean</span>[maxm];</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">getD</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        np[<span class="number">0</span>] = np[<span class="number">1</span>] = <span class="keyword">true</span>;</span><br><span class="line">        d[<span class="number">1</span>] = <span class="number">1</span>;</span><br><span class="line">        tot = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">2</span>; i &lt; maxm; ++i) &#123;</span><br><span class="line">            <span class="keyword">if</span>(np[i] == <span class="keyword">false</span>) &#123;</span><br><span class="line">                p[tot++] = i;</span><br><span class="line">                d[i] = <span class="number">2</span>;</span><br><span class="line">                num[i] = <span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; tot; ++j) &#123;</span><br><span class="line">                <span class="keyword">int</span> x = p[j]*i;</span><br><span class="line">                <span class="keyword">if</span>(x &gt;= maxm) <span class="keyword">break</span>;</span><br><span class="line">                np[x] = <span class="keyword">true</span>;</span><br><span class="line">                <span class="keyword">if</span>(i%p[j] == <span class="number">0</span>) &#123;</span><br><span class="line">                    d[x] = d[i]/(num[i] + <span class="number">1</span>)*(num[i] + <span class="number">2</span>);</span><br><span class="line">                    num[x] = num[i] + <span class="number">1</span>;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    d[x] = <span class="number">2</span>*d[i];</span><br><span class="line">                    num[x] = <span class="number">1</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">SegTree</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> lf, rt;</span><br><span class="line">        <span class="keyword">int</span> mx;</span><br><span class="line">        <span class="keyword">long</span> sum;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> SegTree[] st = <span class="keyword">new</span> SegTree[maxn&lt;&lt;<span class="number">2</span>];</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">PushUp</span><span class="params">(<span class="keyword">int</span> x)</span> </span>&#123;</span><br><span class="line">        st[x].mx = Math.max(st[x &lt;&lt; <span class="number">1</span>].mx, st[x &lt;&lt; <span class="number">1</span> | <span class="number">1</span>].mx);</span><br><span class="line">        st[x].sum = st[x &lt;&lt; <span class="number">1</span>].sum + st[x &lt;&lt; <span class="number">1</span> | <span class="number">1</span>].sum;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Build</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> lf, <span class="keyword">int</span> rt)</span> </span>&#123;</span><br><span class="line">        st[x] = <span class="keyword">new</span> SegTree();</span><br><span class="line">        SegTree now = st[x];</span><br><span class="line">        now.lf = lf;</span><br><span class="line">        now.rt = rt;</span><br><span class="line">        <span class="keyword">if</span>(lf == rt) &#123;</span><br><span class="line">            now.mx = a[lf];</span><br><span class="line">            now.sum = a[lf];</span><br><span class="line">            <span class="keyword">return</span> ;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span> mid = (lf + rt) &gt;&gt; <span class="number">1</span>;</span><br><span class="line">        Build(x &lt;&lt; <span class="number">1</span>, lf, mid);</span><br><span class="line">        Build(x &lt;&lt; <span class="number">1</span> | <span class="number">1</span>, mid + <span class="number">1</span>, rt);</span><br><span class="line">        PushUp(x);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Update</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> lf, <span class="keyword">int</span> rt)</span> </span>&#123;</span><br><span class="line">        SegTree now = st[x];</span><br><span class="line">        <span class="keyword">if</span>(now.mx &lt;= <span class="number">2</span>) <span class="keyword">return</span> ;</span><br><span class="line">        <span class="keyword">if</span>(now.lf == now.rt) &#123;</span><br><span class="line">            now.mx = d[now.mx];</span><br><span class="line">            now.sum = now.mx;</span><br><span class="line">            <span class="keyword">return</span> ;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span> mid = (now.lf + now.rt) &gt;&gt; <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">if</span>(lf &lt;= mid) Update(x &lt;&lt; <span class="number">1</span>, lf, rt);</span><br><span class="line">        <span class="keyword">if</span>(rt &gt; mid) Update(x &lt;&lt; <span class="number">1</span> | <span class="number">1</span>, lf ,rt);</span><br><span class="line">        PushUp(x);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">long</span> <span class="title">Query</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> lf, <span class="keyword">int</span> rt)</span> </span>&#123;</span><br><span class="line">        SegTree now = st[x];</span><br><span class="line">        <span class="keyword">if</span>(lf &lt;= now.lf &amp;&amp; rt &gt;= now.rt) <span class="keyword">return</span> now.sum;</span><br><span class="line">        <span class="keyword">long</span> ret = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> mid = (now.lf + now.rt) &gt;&gt; <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">if</span>(lf &lt;= mid) ret += Query(x &lt;&lt; <span class="number">1</span>, lf, rt);</span><br><span class="line">        <span class="keyword">if</span>(rt &gt; mid) ret += Query(x &lt;&lt; <span class="number">1</span> | <span class="number">1</span>, lf ,rt);</span><br><span class="line">        <span class="keyword">return</span> ret;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        InputStream inputStream = System.in;</span><br><span class="line">        InputReader in = <span class="keyword">new</span> InputReader(inputStream);</span><br><span class="line">        PrintWriter out = <span class="keyword">new</span> PrintWriter(System.out);</span><br><span class="line">        getD();</span><br><span class="line">        <span class="keyword">int</span> n = in.nextInt();</span><br><span class="line">        <span class="keyword">int</span> m = in.nextInt();</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= n; ++i) &#123;</span><br><span class="line">            a[i] = in.nextInt();</span><br><span class="line">        &#125;</span><br><span class="line">        Build(<span class="number">1</span>, <span class="number">1</span>, n);</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= m; ++i) &#123;</span><br><span class="line">            <span class="keyword">int</span> t = in.nextInt();</span><br><span class="line">            <span class="keyword">int</span> l = in.nextInt();</span><br><span class="line">            <span class="keyword">int</span> r = in.nextInt();</span><br><span class="line">            <span class="keyword">if</span>(t == <span class="number">1</span>) &#123;</span><br><span class="line">                Update(<span class="number">1</span>, l, r);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                out.println(Query(<span class="number">1</span>, l, r));</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        out.flush();</span><br><span class="line">        <span class="comment">// Scanner in = new Scanner(System.in);</span></span><br><span class="line">        <span class="comment">// in.close();</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">InputReader</span> </span>&#123;</span><br><span class="line">        <span class="keyword">public</span> BufferedReader reader;</span><br><span class="line">        <span class="keyword">public</span> StringTokenizer tokenizer;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="title">InputReader</span><span class="params">(InputStream stream)</span> </span>&#123;</span><br><span class="line">            reader = <span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(stream), <span class="number">32768</span>);</span><br><span class="line">            tokenizer = <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> String <span class="title">next</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">while</span>(tokenizer == <span class="keyword">null</span> || !tokenizer.hasMoreTokens()) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    tokenizer = <span class="keyword">new</span> StringTokenizer(reader.readLine());</span><br><span class="line">                &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(e);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> tokenizer.nextToken();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">nextInt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Integer.parseInt(next());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">nextLong</span><span class="params">()</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> Long.parseLong(next());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/ACM/" rel="tag"># ACM</a>
          
            <a href="/tags/Tutorial/" rel="tag"># Tutorial</a>
          
            <a href="/tags/CodeForces/" rel="tag"># CodeForces</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/20200225/CodeForces-691-Educational-Codeforces-Round-14/" rel="next" title="CodeForces 691 Educational Codeforces Round 14">
                <i class="fa fa-chevron-left"></i> CodeForces 691 Educational Codeforces Round 14
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  
    <div class="comments" id="comments">
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/star.jpg" alt="linxi">
            
              <p class="site-author-name" itemprop="name">linxi</p>
              <p class="site-description motion-element" itemprop="description">stay hungry, stay foolish</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">15</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">9</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">13</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/linxilinxilinxi" title="https://blog.csdn.net/linxilinxilinxi" rel="noopener" target="_blank">My CSDN</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#A-Water-The-Garden"><span class="nav-number">1.</span> <span class="nav-text">A Water The Garden</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#A-题目大意"><span class="nav-number">1.1.</span> <span class="nav-text">A 题目大意</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#A-解题思路"><span class="nav-number">1.2.</span> <span class="nav-text">A 解题思路</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#A-代码实现"><span class="nav-number">1.3.</span> <span class="nav-text">A 代码实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#B-Tea-Queue"><span class="nav-number">2.</span> <span class="nav-text">B Tea Queue</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#B-题目大意"><span class="nav-number">2.1.</span> <span class="nav-text">B 题目大意</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#B-解题思路"><span class="nav-number">2.2.</span> <span class="nav-text">B 解题思路</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#B-代码实现"><span class="nav-number">2.3.</span> <span class="nav-text">B 代码实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#C-Swap-Adjacent-Elements"><span class="nav-number">3.</span> <span class="nav-text">C Swap Adjacent Elements</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#C-题目大意"><span class="nav-number">3.1.</span> <span class="nav-text">C 题目大意</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#C-解题思路"><span class="nav-number">3.2.</span> <span class="nav-text">C 解题思路</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#C-代码实现"><span class="nav-number">3.3.</span> <span class="nav-text">C 代码实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#E-Connected-Components"><span class="nav-number">4.</span> <span class="nav-text">E Connected Components</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#E-题目大意"><span class="nav-number">4.1.</span> <span class="nav-text">E 题目大意</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#E-解题思路"><span class="nav-number">4.2.</span> <span class="nav-text">E 解题思路</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#E-代码实现"><span class="nav-number">4.3.</span> <span class="nav-text">E 代码实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#F-SUM-and-REPLACE"><span class="nav-number">5.</span> <span class="nav-text">F SUM and REPLACE</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#F-题目大意"><span class="nav-number">5.1.</span> <span class="nav-text">F 题目大意</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#F-解题思路"><span class="nav-number">5.2.</span> <span class="nav-text">F 解题思路</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#F-代码实现"><span class="nav-number">5.3.</span> <span class="nav-text">F 代码实现</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">linxi</span>

  

  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.8.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.0.0</div>





<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">全站共 65.5k 字</span>
</div>

        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>














  
    
    
  
  <script color="25,202,173" opacity="0.8" zindex="-1" count="200" src="/lib/canvas-nest/canvas-nest.min.js"></script>













  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/src/utils.js?v=7.0.0"></script>

  <script src="/js/src/motion.js?v=7.0.0"></script>



  
  


  <script src="/js/src/affix.js?v=7.0.0"></script>

  <script src="/js/src/schemes/pisces.js?v=7.0.0"></script>



  
  <script src="/js/src/scrollspy.js?v=7.0.0"></script>
<script src="/js/src/post-details.js?v=7.0.0"></script>



  


  <script src="/js/src/bootstrap.js?v=7.0.0"></script>



  
  

<script src="//cdn1.lncld.net/static/js/3.11.1/av-min.js"></script>



<script src="//unpkg.com/valine/dist/Valine.min.js"></script>

<script>
  var GUEST = ['nick', 'mail', 'link'];
  var guest = 'nick,mail,link';
  guest = guest.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#comments',
    verify: false,
    notify: false,
    appId: 'LwzdQrGG81bUwkUkAfdPexj1-gzGzoHsz',
    appKey: 'akTaTqH7XeeKc6CPRfB7vbDl',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: guest,
    pageSize: '10' || 10,
    visitor: false
  });
</script>




  


  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  
  
  <script>
    
    function addCount(Counter) {
      var $visitors = $('.leancloud_visitors');
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();

      Counter('get', '/classes/Counter', { where: JSON.stringify({ url }) })
        .done(function({ results }) {
          if (results.length > 0) {
            var counter = results[0];
            
            Counter('put', '/classes/Counter/' + counter.objectId, JSON.stringify({ time: { '__op': 'Increment', 'amount': 1 } }))
            
              .done(function() {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.time + 1);
              })
            
              .fail(function ({ responseJSON }) {
                console.log(`Failed to save Visitor num, with error message: ${responseJSON.error}`);
              })
          } else {
            
              Counter('post', '/classes/Counter', JSON.stringify({ title: title, url: url, time: 1 }))
                .done(function() {
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(1);
                })
                .fail(function() {
                  console.log('Failed to create');
                });
            
          }
        })
        .fail(function ({ responseJSON }) {
          console.log(`LeanCloud Counter Error: ${responseJSON.code} ${responseJSON.error}`);
        });
    }
    

    $(function() {
      $.get('https://app-router.leancloud.cn/2/route?appId=' + 'LwzdQrGG81bUwkUkAfdPexj1-gzGzoHsz')
        .done(function({ api_server }) {
          var Counter = function(method, url, data) {
            return $.ajax({
              method: method,
              url: 'https://' + api_server + '/1.1' + url,
              headers: {
                'X-LC-Id': 'LwzdQrGG81bUwkUkAfdPexj1-gzGzoHsz',
                'X-LC-Key': 'akTaTqH7XeeKc6CPRfB7vbDl',
                'Content-Type': 'application/json',
              },
              data: data
            });
          };
          
            addCount(Counter);
          
        });
    });
  </script>



  

  
  

  
  

  
    
      <script type="text/x-mathjax-config">
  

  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true,
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      
      equationNumbers: {
        autoNumber: "AMS"
      }
    }
  });
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
      for (i = 0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>
<script src="//cdn.jsdelivr.net/npm/mathjax@2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

<style>
.MathJax_Display {
  overflow: auto hidden;
}
</style>

    
  


  

  

  

  

  

  

  

  

  

  

</body>
</html>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>

